package com.example.knowledge.mvvm.adapter

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter
import com.example.knowledge.mvvm.bean.ReportSelectBean
import com.example.knowledge.mvvm.fragment.ReportListFragment

/**
 * @author : lj
 * @date : 2020/7/24 11:23
 */
class ReportPagerAdapter(fm: FragmentManager, titles: MutableList<ReportSelectBean>): FragmentPagerAdapter(fm) {
    private var mtitles:MutableList<ReportSelectBean>?=null
    var fragmentLs: ArrayList<ReportListFragment> = ArrayList()
    init {
        this.mtitles=titles
        mtitles?.forEach {
            fragmentLs.add(ReportListFragment.newInstance(it.type,it.code))
        }
    }
    override fun getItem(position: Int): Fragment {
        return fragmentLs[position]
    }

    override fun getCount(): Int {
        return mtitles!!.size
    }

    override fun getPageTitle(position: Int): CharSequence? {
        return mtitles?.let {
            it[position].name
        }
    }
}